﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;

/// <summary>
/// 去重操作
/// </summary>
/// <author>邓晨露</author>
namespace Common.Utility
{
    public class DistinctCompare<T> : IEqualityComparer<T>
    {
        private Func<T, T, bool> _Equals;

        private Func<T, int> _GetHashCode;

        public DistinctCompare(Func<T, T, bool> equals, Func<T, int> getHashCode)
        {
            this._Equals = equals;
            this._GetHashCode = getHashCode;
        }

        public DistinctCompare(Func<T, T, bool> equals) : this(equals, r => 0)
        {

        }

        public bool Equals(T x, T y)
        {
            return _Equals(x, y);
        }

        public int GetHashCode(T obj)
        {
            return _GetHashCode(obj);
        }
    }
}
